package com.xxzb.pack0721;

import com.xxzb.pack0721.bean.Emp;
import com.xxzb.pack0721.dao.EmpDAO;

import java.util.List;
import java.util.Scanner;

public class App {
    private static EmpDAO edao = new EmpDAO();
    private static Scanner sc = new Scanner(System.in);

    //添加（1）
    public static void a() {
        System.out.println("请输入姓名：");
        String ename = sc.next();
        System.out.println("请输入职位：");
        String job = sc.next();
        System.out.println("请输入上司ID：");
        int mgr = sc.nextInt();
        System.out.println("请输入工资：");
        Double sal = sc.nextDouble();
        System.out.println("请输入奖金：");
        Double comm = sc.nextDouble();
        System.out.println("请输入部门编号：");
        int deptNo = sc.nextInt();
        edao.add(ename, job, mgr, sal, comm, deptNo);
    }

    //添加（2）
    public static void b() {
        System.out.println("请输入姓名：");
        String ename = sc.next();
        System.out.println("请输入职位：");
        String job = sc.next();
        System.out.println("请输入上司id:");
        int mgr = sc.nextInt();
        System.out.println("请输入工资：");
        Double sal = sc.nextDouble();
        System.out.println("请输入奖金：");
        Double comm = sc.nextDouble();
        System.out.println("请输入部门编号：");
        int deptNo = sc.nextInt();
        //封装
        Emp emp = new Emp(ename, job, mgr, sal, comm, deptNo);
        edao.add(emp);
    }

    //删除
    public static void c() {
        System.out.println("请输入需要删除的员工编号：");
        int empNo = sc.nextInt();
        edao.remove(empNo);
    }

    //添加或者修改在一起
    public static void d() {
        System.out.print("请输入姓名：");
        String ename = sc.next();
        System.out.print("请输入职位：");
        String job = sc.next();
        System.out.print("请输入上司ID：");
        int mgr = sc.nextInt();
        System.out.print("请输入工资：");
        double sal = sc.nextDouble();
        System.out.print("请输入奖金：");
        double comm = sc.nextDouble();
        System.out.print("请输入部门ID：");
        int deptNo = sc.nextInt();
        System.out.print("请输入修改的编号：");
        int empNo = sc.nextInt();
        // 封装
        Emp emp = new Emp(ename, job, mgr, sal, comm, deptNo);
        emp.setEmpNo(empNo);
        edao.saveOrUpdate(emp);
    }

    //全表查询
    public static void e() {
        List<Emp> list = edao.find();
        for (int i = 0; i < list.size(); i++) {
            Emp emp = list.get(i);
            System.out.println(emp);
        }
    }

    //按id查询
    public static void f() {
        Emp emp = edao.findByNo(7951);
        System.out.println(emp);

    }

    //分页查询
    public static void g() {
        List<Emp> list = edao.find(11, 5);
        for (int i = 0; i < list.size(); i++) {
            Emp emp = list.get(i);
            System.out.println(emp);
        }
    }

    //模糊查询
    public static void h() {
        List<Emp> list = edao.find("王");
        //遍历集合,取出对象
        for (int i = 0; i < list.size(); i++) {
            Emp emp = list.get(i);
            System.out.println(emp);
        }


    }


    public static void main(String[] args) {
//        a();
//        b();
//        c();
//        e();
//        f();
//        g();
        h();
    }


}
